package com.yimi.yinhepda.db.dao;

import com.j256.ormlite.stmt.QueryBuilder;
import com.yimi.yinhepda.base.BaseApplication;
import com.yimi.yinhepda.db.helper.DbHelper;
import com.yimi.yinhepda.db.table.CheckBalanceTable;
import java.sql.SQLException;
import java.util.List;

/**
 * @author 000432
 * @date 2018/1/10 0010
 */

public class CheckBalanceTableDao extends BaseDao<CheckBalanceTable, Long> {

  public CheckBalanceTableDao() {
    super(DbHelper.getInstance(BaseApplication.getContext()), CheckBalanceTable.class);
  }

  /**
   * 获取差重差方数据
   */
  public List<CheckBalanceTable> getDiffData() {
    try {
      QueryBuilder<CheckBalanceTable, Long> queryBuilder = dao.queryBuilder();
      List<CheckBalanceTable> list = queryBuilder.where().eq("statisticsType", 2).query();
      return list;
    } catch (SQLException e) {
      e.printStackTrace();
    }
    return null;
  }

  /**
   * 判断运单号是否存在
   */
  public boolean exitWayBillData(String userCode, String compCode, String wayBillNum) {
    try {
      QueryBuilder<CheckBalanceTable, Long> queryBuilder = dao.queryBuilder();
      CheckBalanceTable bean =
          queryBuilder.where().eq("userCode", userCode).and().eq("compCode", compCode).and().eq("wayBillNum", wayBillNum).queryForFirst();
      if (bean == null) {
        return false;
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }
    return true;
  }
}
